package com.example.sys

import android.os.Bundle
import androidx.activity.viewModels
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import androidx.viewbinding.ViewBinding
import com.example.lib_common.mvi.BaseActivity
import com.example.sys.databinding.ActivityMainBinding
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

class MainActivity : BaseActivity<ActivityMainBinding,MainViewModel>() {
    override fun createVM(): MainViewModel {
        return viewModels<MainViewModel>().value
    }

    override fun createViewBinding(): ViewBinding {
        return ActivityMainBinding.inflate(inflater)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        bindUiState()
//        v.loginBtn.setOnClickListener{
//            vm.requestTest()
//        }
    }
    private fun bindUiState(){
        lifecycleScope.launch (Dispatchers.Main){
            repeatOnLifecycle(Lifecycle.State.STARTED){
                vm.mutableContainer.uiStateFlow.collect{
                    if (it.entity.statuesCode==200)
                    log("activityEntity"+it.entity.values.data!!.size)
                }
            }
        }
    }
}